home *** CD-ROM | disk | FTP | other *** search
- Path: tank.news.pipex.net!pipex!demon!fe-line.demon.co.uk
- From: faye@fe-line.demon.co.uk (Faye Pearson)
- Newsgroups: comp.lang.c
- Subject: Recursive function -> how do you exit one?
- Date: Mon, 29 Jan 1996 21:08:15 GMT
- Organization: fe-line
- Message-ID: <310d27a6.171790522@news.demon.co.uk>
- References: <4eh1g8$aba@pulp.ucs.ualberta.ca>
- NNTP-Posting-Host: fe-line.demon.co.uk
- X-NNTP-Posting-Host: fe-line.demon.co.uk
- X-Newsreader: Forte Agent .99d/32.168
-
- jbukczyn@gpu.srv.ualberta.ca (Jacob Bukczynski) wrote:
-
- >I'm using a recursive function to search for files. I need
- >it to quit when a user presses Esc.
- >
- >Using
- >
- >return;
- >
- >doesn't seem to work, the funtion runs again. ( I tested
- >this by putting a printf statement in front of the return -
- >it got printed over and over again. )
- >
- >Is there a special way of exiting a recursive function?
-
- You need to return a value which makes all the recursed functions exit
- without further processing.
-
- if the function returns an int then you could return -1 as aborted.
- if it returns a char or char* you can use a (first) character that
- cannot exist in your string. eg 0xff
-
- char* foo()
- {
- result=foo();
- if(*result!=0xff)
- {
- // process things here //
- if (aborted) return "\xff";
- }
- return result;
- }
-
- Does that help?
-
- Faye
- --
- faye@fe-line.demon.co.uk
-